package com.thiruvathukal.examples.dom;

/*
 * XML code examples by George K. Thiruvathukal. Unless noted otherwise
 * this code is covered by GPLv2. We are still working on the licensing
 * text and will update all code and documentation shortly.
 */

import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.Entity;
import org.w3c.dom.EntityReference;
import org.w3c.dom.Notation;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;

import com.thiruvathukal.examples.dom.traversal.DOMNodeEvents;

public class Count1 implements DOMNodeEvents {
	protected int numElements, numAttrs;

	public Count1() {
		numElements = 0;
		numAttrs = 0;
	}

	public void sawAttr(Attr attributes, Object userData) {
		System.out.println("attribute " + attributes.getNodeName());
		System.out.println("attribute " + attributes.getNodeValue());
		numAttrs++;
	}

	public void sawCDATASection(CDATASection cdata, Object userData) {
	}

	public void sawCharacterData(CharacterData cdata, Object userData) {
	}

	public void startDocument(Document document, Object userData) {
		System.out.println("startDocument()");
	}

	public void sawDocumentFragment(DocumentFragment documentFragment,
			Object userData) {
	}

	public void sawDocumentType(DocumentType documentType, Object userData) {
	}

	public void startElement(Element element, Object userData) {
		System.out.println("element " + element.getNodeName());
		numElements++;
	}

	public void endElement(Element element, Object userData) {
		System.out.println("end element " + element.getNodeName());
	}

	public void sawEntity(Entity entity, Object userData) {
	}

	public void startEntityReference(EntityReference entityReference,
			Object userData) {
	}

	public void sawNotation(Notation notation, Object userData) {
	}

	public void sawProcessingInstruction(ProcessingInstruction pi,
			Object userData) {
	}

	public void sawText(Text text, Object userData) {
	}

	public String toString() {
		return "Elements " + numElements + " Attributes " + numAttrs;
	}

	public void endDocument(Document document, Object userData) {
		System.out.println("endDocument()");
	}

	public void endEntityReference(EntityReference entityReference,
			Object userData) {
		System.out.println("endEntityReference()");
	}
}
